package org.hang.gift.strategy.impl;



import org.hang.gift.strategy.ShopCarDataSyncKeyGroupStrategy;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * hash策略,进行分组
 */
public class ShopCarDataSyncKeyGroupByHashStrategy implements ShopCarDataSyncKeyGroupStrategy {

    private Integer num = 100;

    public ShopCarDataSyncKeyGroupByHashStrategy(){

    }

    public ShopCarDataSyncKeyGroupByHashStrategy(Integer num){
        this.num = num;
    }

    @Override
    public Map<Integer, List<String>> group(Set<String> keys) {

        Map<Integer, List<String>> listMap = keys.stream().collect(Collectors.groupingBy(x -> x.hashCode() % num));

        return listMap;
    }
}
